package com.example.cpms.service.impl;

import com.example.cpms.entity.Building;
import com.example.cpms.entity.Propety;
import com.example.cpms.mapper.BuildingMapper;
import com.example.cpms.mapper.PropetyMapper;
import com.example.cpms.service.PropetyService;
import com.example.cpms.utils.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class PropetyServiceImpl implements PropetyService {

    @Autowired
    private PropetyMapper propetyMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String username, String buildingname) {
        PageHelper.startPage(page, pageSize);
        List<Propety> propetyList = propetyMapper.list(username, buildingname);
        Page<Propety> p = (Page<Propety>) propetyList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void delete(Integer id) {
        propetyMapper.delete(id);
    }

    @Override
    public void add(Propety propety) {

        propety.setStartTime(LocalDateTime.now());
        propety.setEndTime(LocalDateTime.now().plusDays(7));

        propetyMapper.insert(propety);

    }

    @Override
    public void update(Propety propety) {
        propetyMapper.update(propety);
    }
}
